package com.agung.wonogirimaps.util;

import com.agung.wonogirimaps.BuildConfig;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

public class Utils
{

	public static final String			API				= "http://api.pratamawijaya.com/wonogiri/service.php";
	public static final String			API_CATEGORY	= API + "?get=category";
	public static final String			API_LOCATION	= API
																+ "?get=location&cat_id=";
	public static final String			API_HOTEL		= API + "?get=hotel";
	public static final String			API_RUMAH_MAKAN	= API
																+ "?get=rumahmakan";
	public static final String			API_SEARCH		= API
																+ "?get=search&term=";

	private static final String			PREF_NAME		= "wonogiri_prefs";
	private static final String			USERLOGIN		= "login_user";
	public static final String			EMAIL			= "email_user";
	public static final String			NAME			= "nama_user";
	private static SharedPreferences	sh;

	/**
	 * Method untuk debugging aplikasi
	 * 
	 * @param TAG
	 *            class dimana debugging dijalankan
	 * @param msg
	 *            pesan yang akan ditampilkan
	 */
	public static void TRACE(String TAG, String msg)
	{
		if (BuildConfig.DEBUG)
		{
			Log.d(TAG, msg);
		}
	}

	/**
	 * cek user login
	 * 
	 * @param con
	 *            context
	 * @return true if userlogi
	 */
	public static boolean isUserLogin(Context con)
	{
		sh = con.getSharedPreferences(PREF_NAME, 0);

		return sh.getBoolean(USERLOGIN, false);
	}

	/**
	 * Set user login
	 * 
	 * @param con
	 *            Context
	 * @param isLogin
	 *            login parameter (true|false)
	 */
	public static void setUserLogin(Context con, boolean isLogin)
	{
		sh = con.getSharedPreferences(PREF_NAME, 0);
		SharedPreferences.Editor editor = sh.edit();
		editor.putBoolean(USERLOGIN, isLogin);
		editor.commit();
	}

	/**
	 * 
	 * @param con
	 *            Context
	 * @param saveTo
	 *            disimpan ke ?
	 * @param data
	 *            data yang disimpan
	 */
	public static void setDataStringtoSP(Context con, String saveTo, String data)
	{
		sh = con.getSharedPreferences(PREF_NAME, 0);
		SharedPreferences.Editor editor = sh.edit();
		editor.putString(saveTo, data);
		editor.commit();
	}

	/**
	 * 
	 * @param con
	 *            Context
	 * @param getWhat
	 *            yang diambil apa.?
	 * @return data
	 */
	public static String getDataStringSP(Context con, String getWhat)
	{
		sh = con.getSharedPreferences(PREF_NAME, 0);
		return sh.getString(getWhat, "null");
	}

}
